﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using GSQ.BusinessEntities;
using GSQ.BusinessLogic;
using UIapp.Interfaces;

namespace UIapp.Vistas
{
    public partial class frmNcf : Plantillas.frmViewPlantilla, IPantalla
    {
        public frmNcf()
        {
            InitializeComponent();
            this.entityCollection = new List<NCF>();
            this.Buscar();
        }

        #region Variables
        List<NCF> entityCollection;
        #endregion

        #region Implementacion IPantalla
        public int ComandosSoportados
        {
            get
            {
                return (int)ComandosPantalla.Modificar | (int)ComandosPantalla.Buscar;

            }
        }

        public void Nuevo()
        {
            throw new NotImplementedException();
        }

        public void Modificar()
        {
            if (this.bindingSource.Count > 0)
            {
                Dialogos.frmNcf frm = new Dialogos.frmNcf((NCF)this.radGridView.CurrentRow.DataBoundItem);
               // frm.MdiParent = this.MdiParent;
                frm.ShowDialog();
                this.Buscar();

            }
        }

        public void Eliminar()
        {
            throw new NotImplementedException();
        }

        public void Refrescar()
        {
            this.Buscar();
        }

        public void Buscar()
        {
            this.backgroundWorker.RunWorkerAsync();
            Comun.ShowLoadingFRM();
        }

        public void AgregarProducto(Controles.TransferEntity tranferEntity)
        {
            throw new NotImplementedException();
        }
        #endregion

        #region Tratamiento de eventos

        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Listar();
        }

        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Comun.CloseLoadingFRM();
            if (e.Error != null)
                Comun.ShowMessage(e.Error);
            else
                this.bindingSource.DataSource = this.entityCollection.Where(a => a.ACTIVO == true ).ToList();
        }

        #endregion

        #region Metodos auxiliares
        public void Listar()
        {
            this.entityCollection.Clear();
            this.entityCollection = new NcfBL().GetAll();
        }
        #endregion
    }
}
